<?php $this->load->view('common/header');?>

<body>
<?php $this->load->view('common/user_center');?>
<div class="main_box">
    <?php $this->load->view('common/menu');?>
    <div class="right_box f_r">
        <div class="title">
        	<span class="f_l">产品管理</span>
        </div>
        <div class="ifrom_list">
        	<dl>
            	<dt>分类：</dt>
                <dd>
                	<span class="input">
                    	<select id="good_category" name="good_category" class="select2 rcol-xs-10 col-sm-5">
                            <option value="0">请选择产品类型</option>
                            <?php if(isset($category2) && !empty($category2)){ ?>
                                <?php foreach ($category2 as $key2 =>$val2 ) { ?>
                                    <option value="<?php echo $val2['id'];?>" <?php if(isset($goods) && $goods['good_category'] == $val2['id']){?>selected="selected"<?php } ?>
                                    ><?php echo $val2['category_name'];?></option>
                                <?php }?>
                            <?php }?>
                        </select>
                    </span>
                </dd>
            </dl>
            <dl>
            	<dt>产品名称：</dt>
                <dd>
                	<span class="input">
                    	<input placeholder="请输入产品名称" name="good_title" id="good_title" value="<?php echo $goods['good_title']?>">
                    </span>
                </dd>
            </dl>
            <dl>
            	<dt>规格：</dt>
                <dd>
                	<span class="input">
                    	<input placeholder="请输入规格" name="good_memo" id="good_memo" value="<?php echo $goods['good_memo']?>">
                    </span>
                </dd>
            </dl>
            <dl>
            	<dt>单价：</dt>
                <dd>
                	<span class="input">
                    	<input placeholder="请输入单价" name="good_price" id="good_price" value="<?php echo $goods['good_price']?>">
                    </span>
                </dd>
            </dl>
            <dl>
                <dt>料号：</dt>
                <dd>
                	<span class="input">
                    	<textarea placeholder="请输入产品料号" name="good_part_number" id="good_part_number"><?php echo $goods['good_part_number']?></textarea>
                    </span>
                </dd>
            </dl>
            <dl>
            	<dt>制作工艺：</dt>
                <dd>
                	<span class="input">
                    	<textarea placeholder="请输入制作工艺" name="good_content" id="good_content"><?php echo $goods['good_content']?></textarea>
                    </span>
                </dd>
            </dl>
            <dl>
            	<dt>工艺图纸：</dt>
                <dd>
                	<a href="javascript:;" class="up a_upload">
                    	<input type="file">
                    	点击上传
                    </a>
                    <div id="imgbox" <?php if(empty($goods['good_cover'])){?>style="display: none" <?php } ?>>
                        <?php if(!empty($goods['good_cover'])){?>
                            <img src="<?php echo $goods['good_cover']; ?>" alt="" width="100px">
                        <?php } ?>
                    </div>
                    <input type="hidden" name="good_cover" id="good_cover" value="<?php echo $goods['good_cover']?>"">
                </dd>
            </dl>
            <dl>
            	<dt>&nbsp;</dt>
                <dd>
                    <input type="hidden" id="good_id" name="good_id" value="<?php echo $goods['good_id']?>">
                	<a href="javascript:;" id="doEdit" class="nav">确定</a>
                </dd>
            </dl>
        </div>
    </div>
</div>
<!--]] user -->
<!-- coypright [[-->
<?php //$this->load->view('common/footer');?>
<!--]] coypright -->
<script src="<?php echo $viewmulu;?>js/jquery.core.image.upload.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var uid = "<?php echo $user['user_id'];?>";
        $(".a_upload").coreImageUpload ({
            url: baseurl+'index.php/upload/upload_goods?uid='+uid+'&name=cover',
            inputOfFile: 'cover',
            uploadedCallback: function (result) {
                if(result.status==1){
                    $("#imgbox").html();
                    var img = '<br /><img src="'+result.url+'">';
                    $("#good_cover").val(result.url);
                    $("#imgbox").html(img);
                    $("#imgbox").show();
                }else{
                    layer.msg(result.msg,{offset:"80px"});
                }
            }
        });

        // 提交
        $("#doEdit").on("click",function(){
            var good_id = $("#good_id").val();
            var good_category = $("#good_category").val();
            var good_title = $("#good_title").val();
            var good_memo = $("#good_memo").val();
            var good_price = $("#good_price").val();
            var good_content = $("#good_content").val();
            var good_part_number = $("#good_part_number").val();
            var good_cover = $("#good_cover").val();
            if (good_title=="") {
                layer.msg('请填写产品名称');
                return false;
            }
            if (good_price=="") {
                layer.msg('请填写产品价格');
                return false;
            }
            var URL= baseurl+"index.php/vip/product/edit";
            $.ajax({
                type: "post",
                url: URL,
                dataType:'json',
                data: {
                    'good_category':good_category,
                    'good_id':good_id,
                    'good_title':good_title,
                    'good_memo':good_memo,
                    'good_price':good_price,
                    'good_content':good_content,
                    'good_cover':good_cover,
                    'good_part_number':good_part_number,
                    'csrf_test_name': ci_csrf_token()
                },
                success: function(data){
                    if(data.status == 200){
                        layer.msg('编辑成功', {
                            time: 1000, //1s后自动关闭
                            shade: 0.1
                        },function () {
                            window.location.href = "<?php echo site_url(V_URL.'product/index');?>";
                        });
                    }else{
                        layer.msg(data.msg);
                        return false;
                    }

                }
            });
        });
    });
</script>
</body>
</html>
